<template>
  <div class="page">
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">
            <div class="layui-card-body">
              <div class="layui-form" lay-filter='djlist' style="font-size:15px;">

                  <div class="layui-form-item">
                  <label class="layui-form-label">会员等级</label>
                  <div class="layui-input-inline">
                    <select name="gradeSetting" lay-filter="gradeSetting" v-model="itemData.gradeSetting.id">
                      <option v-for="(item,index) in djlist" :value="item.id" :key="index">{{item.name}}</option>
                    </select>
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">开户费(元)</label>
                  <div class="layui-input-inline" style="width: 190px;">
                    <input
                      type="text"
                      name
                      placeholder=""
                      v-model="itemData.amount"
                      autocomplete="off"
                      class="layui-input"
                    />
                  </div>
                </div>          
								<div class="layui-form-item">
                  <label class="layui-form-label">状态</label>
                  <div class="layui-input-inline">
                    <select name="status" lay-filter="status" v-model="itemData.status">
                      <option value="ENABLE">启用</option>
                      <option value="DISABLE">禁用</option>
                    </select>
                  </div>
                  
                </div>
                <div class="layui-form-item">
						      <label class="layui-form-label">类别图片</label>
						      <div class="layui-input-inline">
						         <div class="layui-upload">
										  <button type="button" class="layui-btn" id="layuiadmin-upload-useradmin">上传图片</button>
										  <div class="layui-upload-list">
										    <img class="layui-upload-img" id="logo" :src="itemData.logo?itemData.logo:'http://kedoujfpc.tongdui365.com/static/common/image/zwyl.jpg'" width="100" height="100" style="border:1px solid #eee;">
										    <p id="demoText"></p>
										  </div>
										</div>   
						      </div>
						      
						    </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">解冻比例</label>
                  <div class="layui-input-inline">
                    <input
                      type="number"
                      name="balanceUc"
                      placeholder="请输入,"
                      v-model="itemData.bondFreeze"
                      autocomplete="off"
                      class="layui-input"
                    />
                  </div>
                  <div class="layui-form-mid">‰</div>
                  <div class="layui-form-mid layui-word-aux">千分比,如千分之一则输入1</div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">推荐人返点比例</label>
                  <div class="layui-input-inline" >
                    <input
                      type="number"
                      name="balanceXfgf"
                      placeholder="请输入"
                      v-model="itemData.backRebate"
                      autocomplete="off"
                      class="layui-input"
                    />
                  </div>
                  <div class="layui-form-mid">‰</div>
                  <div class="layui-form-mid layui-word-aux">千分比,如千分之一则输入1</div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">返点推荐解冻人数</label>
                  <div class="layui-input-inline" style="width: 190px;">
                    <input
                      type="number"
                      name="balanceCreditUc"
                      placeholder="请输入"
                      v-model="itemData.epicyclenum"
                      autocomplete="off"
                      class="layui-input"
                    />
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">上级区域返点比例</label>
                  <div class="layui-input-inline" style="width: 190px;">
                    <input
                      type="number"
                      name="redFrequency"
                      placeholder="请输入"
                      v-model="itemData.parentRatio"
                      autocomplete="off"
                      class="layui-input"
                    />
                  </div>
                  <div class="layui-form-mid">‰</div>
                  <div class="layui-form-mid layui-word-aux">千分比,如千分之一则输入1</div>
                </div>
                
                <div class="layui-form-item">
                  <label class="layui-form-label">上级商圈返点比例</label>
                  <div class="layui-input-inline" style="width: 190px;">
                    <input
                      type="number"
                      name="redFrequency"
                      placeholder="请输入"
                      v-model="itemData.parentDistrictRatio"
                      autocomplete="off"
                      class="layui-input"
                    />
                  </div>
                  <div class="layui-form-mid">‰</div>
                  <div class="layui-form-mid layui-word-aux">千分比,如千分之一则输入1</div>
                </div>
                
                <div class="layui-form-item" id="test1">
                  <label class="layui-form-label">间接推荐奖励的比</label>
                  <div class="layui-input-inline" style="width: 190px;">
                    <input
                      type="number"
                      name="stackRebate"
                      placeholder="请输入"
                      v-model="itemData.indirectRatio"
                      autocomplete="off"
                      class="layui-input"
                    />
                  </div>
                  <div class="layui-form-mid">‰</div>
                  <div class="layui-form-mid layui-word-aux">千分比,如千分之一则输入1</div>
                </div>

                

 


                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <button
                      class="layui-btn layui-btn-normal"
                      lay-submit
                      lay-filter="setmyinfo"
                      @click="sure"
                    >确认</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "gradeadd",
  data() {
    return {
      id: "",
      itemData: {
      	  "amount": 0,
			  "status": "ENABLE",
			  "logo": "",
			  "bondFreeze": 0,
			  "backRebate": 0,
			  "epicyclenum": 0,
			  "parentRatio": 0,
			  "parentDistrictRatio": 0,
			  "indirectRatio": 0,
        gradeSetting:{
            id:"",
            name:""
        }//会员等级
      },
      djlist: [], //会员等级

    };
  },
  mounted() {
    var _this = this;
    this.getdj(); //会员等级
    layui.use('upload', function(){
		  var upload = layui.upload;
		  var uploadInst = upload.render({
		    elem: '#layuiadmin-upload-useradmin',//绑定元素
		    data:{
		    	type:3
		    }
		    ,url:imguploadurl//上传接口
		    ,done: function(res){
		    	layer.msg('上传成功');
		    	 _this.itemData.logo=res.msg;
		    }
		    ,error: function(){
		      layer.msg('上传失败');
		    }
		  });
		});
    window.getdates = this.getdates;
  },
  methods: {
    getdates: function (data) {
      //回选详情
      var _this = this;
      var url = "/profit/aapi/v1.9/bond-grade-setting/" + data.id;
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        //alert(JSON.stringify(ret))
        _this.itemData = ret.data;
         _this.itemData.amount=ret.data.amount/100
        _this.id = ret.data.id;
       
      });
    },
    getdj: function () {
      var _this = this;
      var url = "/profit/aapi/v1.9/grade-type-setting/grade/settingList";
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        _this.djlist = ret.data;
      });
    },
    sure: function () {
      var _this = this;
      var hat = "POST";
      var dates = _this.itemData;
      dates.amount=_this.itemData.amount*100
      if (_this.id) {
        dates.id = _this.id;
        hat = "PUT";
      }
      var url = "/profit/aapi/v1.9/bond-grade-setting";
      //alert(JSON.stringify(dates))
      ajaxRequest(url, hat, "json", dates, function (ret, err) {
        layer.msg("操作成功");
        setTimeout(function () {
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);
            parent.location.reload();
        }, 1000);
      });
    },
  },
  updated: function () {
    var _this = this;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
      form.render(null,'gradeSetting');
      form.on("select(gradeSetting)", function (data) {
        //等级类型
        _this.itemData.gradeSetting.id = data.value;
        if(data.value==1){
            document.getElementById("test1").style.display="";
            document.getElementById("test2").style.display="";
        }else if(data.value==2){
            document.getElementById("test1").style.display="none";
            document.getElementById("test2").style.display="";
        }else {
            document.getElementById("test1").style.display="none";
            document.getElementById("test2").style.display="none";
        }
      });
      form.on("select(status)", function (data) {
      	_this.itemData.status=data.value
      });
      
    });
  },
};
</script>
<style>
</style>